package nina.yiyou.attendance.s30pattern.output


import nina.yiyou.salary.process.global.GlobalResultMaker

import java.nio.file.Path
import java.time.LocalDate
import java.time.temporal.ChronoUnit
import java.util.stream.Collectors
import java.util.stream.IntStream

class DetailPatternGenerator {

  DetailPatternGenerator(List<Map> employeeResult, GlobalResultMaker.Result globalResult) {
    _employeeResult = employeeResult
    _globalResult = globalResult
  }

  void generate() {
    Path out = _globalResult.resolvePath('out.考勤图案')

    println('TODO: 生成星星月亮')
    new PatternXlsxExporter(out, makeResultHeader(), _employeeResult).export()
  }

  /**
   * @see nina.yiyou.attendance.s30pattern.compute.PatternEmployeeMerger#makePartLine
   */
  private List<String> makeResultHeader() {
    GlobalResultMaker.Salary salary = _globalResult.salaryTime()
    LocalDate start = salary.start()
    LocalDate end = salary.end()

    List<String> dateList = IntStream.range(0, ChronoUnit.DAYS.between(start, end) as int)
        .mapToObj { start.plusDays(it) }
        .map { '计算3.' + it.toString() }
        .collect(Collectors.toList())

    return ['计算.工号', '明细.姓名', '明细.部门', '计算3.时间'] + dateList
  }

  private final List<Map> _employeeResult

  private final GlobalResultMaker.Result _globalResult
}
